package com.example.shardingjdbc.shardingjdbcdemo.config;

import org.apache.shardingsphere.api.sharding.standard.PreciseShardingAlgorithm;
import org.apache.shardingsphere.api.sharding.standard.PreciseShardingValue;

import java.util.Collection;

/**
 * @author: HLB
 * @desc:
 * @version: V1.0.0
 */
public class ShardingAlgorithm implements PreciseShardingAlgorithm<String> {
    /**
     * sql 中 = 操作时，table的映射
     　　　*　　根据传进来的日期命名表名称
     */
    @Override
    public String doSharding(Collection<String> tableNames, PreciseShardingValue<String> shardingValue) {
        String tableName = shardingValue.getLogicTableName();
        String key = shardingValue.getValue().substring(0, 6);
        return tableName.concat("_").concat(key);
    }
}
